#include <iostream>
#include <vector>
#include <algorithm>

int method1(int num)
{
    int cnt = 0;
    while (num > 1)
    {
        if (num % 2 == 1)
        {
            if (num == 3 || num & 2 == 0)
            {
                num--;
            }
            else
            {
                num++;
            }
        }
        else
        {
            num = num / 2;
        }
        cnt++;
    }

    return cnt;
}

void method2(int num, int cnt, std::vector<int> &cnt_list)
{
    if (num == 1)
    {
        cnt_list.push_back(cnt);
        return;
    }

    if (num % 2 == 0)
    {
        method2(num / 2, cnt + 1, cnt_list);
    }
    else
    {
        method2(num + 1, cnt + 1, cnt_list);
        method2(num - 1, cnt + 1, cnt_list);
    }
}

int main()
{
    int num;
    std::cin >> num;

    // int cnt = method1(num);
    int cnt = 0;
    std::vector<int> cnt_list;
    method2(num, cnt, cnt_list);
    auto minv = *min_element(cnt_list.begin(), cnt_list.end());
    std::cout
        << minv << std::endl;
    return 0;
}